package com.zj.juc.study.cas;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import java.util.concurrent.atomic.AtomicStampedReference;

/**
 * @author 自己的名字
 * @version 1.0.0
 * @ClassName CasAbaProblemResolveDemo
 * @Description 运用版本号解决aba问题
 * @createTime 2025年01月02日 23:00
 */
public class CasAbaProblemResolveDemo {

    static AtomicStampedReference<Integer> atomicReference = new AtomicStampedReference<>(100,1);

    public static void main(String[] args) {
        new Thread(()->{
            int firstStamp = atomicReference.getStamp();
            try {
                TimeUnit.SECONDS.sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            atomicReference.compareAndSet(100,101,firstStamp,firstStamp+1);
        },"t1").start();
    }
}
